package com.dcbeida.changepassword;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.InputType;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import com.dcbeida.R;
import com.dcbeida.activity.BaseActivity;
import com.dcbeida.activity.login.LoginContract;
import com.dcbeida.activity.login.LoginPresenter;

/**
 * Created by hp on 2016/7/26.
 */
public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener,ChangePsContract.View{



    @Bind(R.id.img_back)
    ImageView img_back;

    @Bind(R.id.et_jmm)
    EditText et_jmm;

    @Bind(R.id.et_xmm)
    EditText et_xmm;

    @Bind(R.id.et_qrxmm)
    EditText et_qrxmm;

    @Bind(R.id.tv_confim)
    TextView tv_confim;

    @Bind(R.id.cb_select)
    CheckBox cb_select;


    private ChangePsContract.Present mPresent;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_changepassword;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initListeners();
        initPresenter();

    }

    private void initPresenter() {
        mPresent = new ChangePsPresenter(this, this);
    }

    private void initListeners() {
        img_back.setOnClickListener(this);
        tv_confim.setOnClickListener(this);
        cb_select.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.img_back:
                finish();
                break;
            case R.id.tv_confim:
                mPresent.change();
                break;

            case R.id.cb_select:
                if (cb_select.isChecked()) {
                    et_jmm.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                    et_xmm.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                    et_qrxmm.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                }else {
                    et_jmm.setInputType((InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD));
                    et_xmm.setInputType((InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD));
                    et_qrxmm.setInputType((InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD));

                }
                break;
        }
    }

    @Override
    public String getOldPassword() {
        return et_jmm.getText().toString();
    }

    @Override
    public String getNewPassword() {
        return et_xmm.getText().toString();
    }

    @Override
    public String getModfiyNewPassword() {
        return et_qrxmm.getText().toString();
    }

    @Override
    public void changePsSuccess() {
        this.finish();
    }

    @Override
    public void showATip(String msg) {
        showTip(msg);
    }

    @Override
    public void showATip(int resId) {
        showTip(getString(resId));
    }

    @Override
    public void setPresenter(ChangePsContract.Present presenter) {

    }
}
